/*
 * API Setting and Mesh Core setting file
 *
 */
#pragma once

//ssv add-->
#define CONFIG_BLE_GATTC_UNRESPONSIVE_TIMEOUT_MS 5000
#define CONFIG_BLE_EXTENDED_ADV 1
#define CONFIG_BLE_MULTI_ADV_INSTANCES 2
#define CONFIG_BLE_50_FEATURE_SUPPORT 0 //other feature exclude EXTENDED_ADV

#if CONFIG_BLE_EXTENDED_ADV
#define MYNEWT_VAL_BLE_EXT_ADV (1)
#define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (CONFIG_BLE_MULTI_ADV_INSTANCES)
#else
#define MYNEWT_VAL_BLE_EXT_ADV (0)
#define MYNEWT_VAL_BLE_MULTI_ADV_INSTANCES (0)
#endif

#define CONFIG_BLE_MESH_PTS 0
#define CONFIG_BT_STACK_NO_LOG 1

#if (BLE_GATTS_EN && BLE_GATTC_EN == 0)
#define GATTS_INCLUDED 1
#define GATTC_INCLUDED 0
#define  BLE_INCLUDED  1
#define SCAN_QUEUE_CONGEST_CHECK 1
#elif (BLE_GATTS_EN == 0 && BLE_GATTC_EN)
#define GATTS_INCLUDED 0
#define GATTC_INCLUDED 1
#define  BLE_INCLUDED  1
#define SCAN_QUEUE_CONGEST_CHECK 1
#elif (BLE_GATTS_EN == 0 && BLE_GATTC_EN == 0 && BLE_GAP_EN)
#define GATTS_INCLUDED 0
#define GATTC_INCLUDED 0
#define  BLE_INCLUDED  1
#define SCAN_QUEUE_CONGEST_CHECK 1
#elif (BLE_GATTS_EN && BLE_GATTC_EN && BLE_GAP_EN)
#define GATTS_INCLUDED 1
#define GATTC_INCLUDED 1
#define  BLE_INCLUDED  1
#define SCAN_QUEUE_CONGEST_CHECK 1
#elif (BLE_GAP_EN == 0 && BLE_GATTS_EN == 0 && BLE_GATTS_EN == 0)
#define GATTS_INCLUDED 0
#define GATTC_INCLUDED 0
#define  BLE_INCLUDED  0
#define SCAN_QUEUE_CONGEST_CHECK 0
#endif

//#define GATTS_INCLUDED 1
//#define GATTC_INCLUDED 1
//#define  BLE_INCLUDED  1 /* enable for copy from bluedroid*/


#define DEV_UUID {0xdd, 0xdd}
#define CONFIG_PERFORMANCE_CLIENT_MODEL 1
#define CONFIG_BLE_MESH_GENERIC_ONOFF_CLI 1
#define CONFIG_NEWLIB_NANO_FORMAT 1
#define CONFIG_BTC_TASK_STACK_SIZE 5120//1024
#define CONFIG_BLE_MESH_ADV_TASK_STACK_SIZE 4096
#define CONFIG_BLE_MESH_TEST_TASK_STACK_SIZE 2048
#define CONFIG_BLE_MESH_FRIEND 1
#define CONFIG_BLE_MESH_DBG 0
#define CONFIG_BLE_MESH_NET_BUF_LOG 1
#define CONFIG_BLE_MESH_RELAY_DONT_SEND_CRITERIA 3

#define CONFIG_BLE_MESH_RELAY_ADV_SSV 1  /* ssv use osal do xQueueSelectFromSet*/
#define CONFIG_BLE_MESH_RELAY_ADV_BUF 1

#define CONFIG_BLE_MESH_BLOCK_TRANSMIT_SET 0

#define CONFIG_BLE_MESH_OTHER_MODEL_EN MESH_BLE_OTHER_MODEL_EN
#define CONFIG_BLE_MESH_GPIO_DBG 0

#if CONFIG_BLE_MESH_GPIO_DBG
#define POOL_HIGH_GPIO(x)    \
    if (x)  \
        *((u32*)(HW_IO_REG->IO_PO)) |= (0x1 << x);  \

#define POOL_LOW_GPIO(x)    \
    if (x)  \
        *((u32*)(HW_IO_REG->IO_PO)) &= ~(0x1 << x);  \

#define CONFIG_BLE_MESH_GPIO_TEST_START_END GPIO_02
#define CONFIG_BLE_MESH_GPIO_TEST_FAIL GPIO_25
#define CONFIG_BLE_MESH_GPIO_TEST_MSG_SYNC_ADV_START_END GPIO_24
#define CONFIG_BLE_MESH_GPIO_TEST_ACK_START_END SIO_13
#else
#define CONFIG_BLE_MESH_GPIO_TEST_START_END 0
#define CONFIG_BLE_MESH_GPIO_TEST_FAIL 0
#define CONFIG_BLE_MESH_GPIO_TEST_MSG_SYNC_ADV_START_END 0
#define CONFIG_BLE_MESH_GPIO_TEST_ACK_START_END 0
#endif
/* Friend Parameter*/
#define CONFIG_BLE_MESH_FRIEND_SUB_LIST_SIZE 3
#define CONFIG_BLE_MESH_FRIEND_LPN_COUNT 3
#define CONFIG_BLE_MESH_FRIEND_SEG_RX 3
#define CONFIG_BLE_MESH_FRIEND_QUEUE_SIZE 16
#define CONFIG_BLE_MESH_FRIEND_RECV_WIN 30
#if SUPPORT_FFS
#define CONFIG_BLE_MESH_SETTINGS 1
#else
#define CONFIG_BLE_MESH_SETTINGS 0
#endif
#define CONFIG_BLE_MESH_SEQ_STORE_RATE 256
#define CONFIG_BLE_MESH_RPL_STORE_TIMEOUT 20000
#define CONFIG_BLE_MESH_STORE_TIMEOUT 10000
#define CONFIG_BLE_MESH_USE_DUPLICATE_SCAN 1
#define CONFIG_BLE_MESH_EVENT_QUEUE_SIZE 16
#define CONFIG_BLE_HCI_HISTORY_DBG 0
//ssv add<--

#define CONFIG_BT_ENABLED 1
#define CONFIG_BTDM_CTRL_MODE_BLE_ONLY 1
#define CONFIG_BTDM_CTRL_BLE_MAX_CONN 3
#define CONFIG_BTDM_CTRL_BR_EDR_SCO_DATA_PATH_EFF 0
#define CONFIG_BTDM_CTRL_BLE_MAX_CONN_EFF 3
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_ACL_CONN_EFF 0
#define CONFIG_BTDM_CTRL_BR_EDR_MAX_SYNC_CONN_EFF 0
#define CONFIG_BTDM_CTRL_PINNED_TO_CORE_0 1
#define CONFIG_BTDM_CTRL_PINNED_TO_CORE 0
#define CONFIG_BTDM_CTRL_HCI_MODE_VHCI 1
#define CONFIG_BTDM_BLE_DEFAULT_SCA_250PPM 1
#define CONFIG_BTDM_BLE_SLEEP_CLOCK_ACCURACY_INDEX_EFF 1
#define CONFIG_BTDM_BLE_SCAN_DUPL 1
#define CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE 1
#define CONFIG_BTDM_SCAN_DUPL_TYPE 2
#define CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE 100
#define CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN 1
#define CONFIG_BTDM_MESH_DUPL_SCAN_CACHE_SIZE 100
#define CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED 1
#define CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP 1
#define CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM 100
#define CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD 20
#define CONFIG_BT_NIMBLE_ENABLED 1
#define CONFIG_BT_RESERVE_DRAM 0xdb5c
#define CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL 1
#define CONFIG_BT_NIMBLE_MAX_CONNECTIONS 4
#define CONFIG_BT_NIMBLE_MAX_BONDS 3
#define CONFIG_BT_NIMBLE_MAX_CCCDS 8
#define CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM 0
#define CONFIG_BT_NIMBLE_PINNED_TO_CORE_0 1
#define CONFIG_BT_NIMBLE_PINNED_TO_CORE 0
#define CONFIG_BT_NIMBLE_TASK_STACK_SIZE 2048

#if BLE_SLAVE_EN
#define MYNEWT_VAL_BLE_ROLE_PERIPHERAL 1
#define MYNEWT_VAL_BLE_ROLE_BROADCASTER 1
#else
#define MYNEWT_VAL_BLE_ROLE_PERIPHERAL 0
#define MYNEWT_VAL_BLE_ROLE_BROADCASTER 0
#endif

#if BLE_MASTER_EN
#define MYNEWT_VAL_BLE_ROLE_CENTRAL 1
#else
#define MYNEWT_VAL_BLE_ROLE_CENTRAL 0
#endif

#if BLE_SCAN_EN
#define MYNEWT_VAL_BLE_ROLE_OBSERVER 1
#else
#define MYNEWT_VAL_BLE_ROLE_OBSERVER 0
#endif

#define MYNEWT_VAL_BLE_GATT_DISC_ALL_CHRS (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_DISC_ALL_DSCS (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_DISC_ALL_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_DISC_CHR_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_DISC_SVC_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_FIND_INC_SVCS (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_READ (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_READ_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_READ_MULT (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_READ_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_SIGNED_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_WRITE (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_WRITE_LONG (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_WRITE_NO_RSP (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_WRITE_RELIABLE (MYNEWT_VAL_BLE_ROLE_CENTRAL)
#define MYNEWT_VAL_BLE_GATT_DISC_CHRS_UUID (MYNEWT_VAL_BLE_ROLE_CENTRAL)

#define CONFIG_BT_NIMBLE_NVS_PERSIST 1
#if BLE_SM_LEGACY_EN
#define MYNEWT_VAL_BLE_SM_LEGACY 1
#else
#define MYNEWT_VAL_BLE_SM_LEGACY 0
#endif

#if BLE_SM_SC_EN
#define MYNEWT_VAL_BLE_SM_SC 1
#else
#define MYNEWT_VAL_BLE_SM_SC 0
#endif

#define CONFIG_BT_NIMBLE_SVC_GAP_DEVICE_NAME "ssv"
#define CONFIG_BT_NIMBLE_GAP_DEVICE_NAME_MAX_LEN 31
#define CONFIG_BT_NIMBLE_ATT_PREFERRED_MTU 256
#define CONFIG_BT_NIMBLE_SVC_GAP_APPEARANCE 0x0
#define CONFIG_BT_NIMBLE_ACL_BUF_COUNT 12
#define CONFIG_BT_NIMBLE_ACL_BUF_SIZE 255
#define CONFIG_BT_NIMBLE_HCI_CMD_COUNT 1
#define CONFIG_BT_NIMBLE_HCI_EVT_BUF_SIZE 255
#define CONFIG_BT_MIN_AVAILABLE_BUFFER_SIZE_TO_NIMBLE 3
#define CONFIG_BT_NIMBLE_HCI_EVT_HI_BUF_COUNT CONFIG_BLE_MESH_EVENT_QUEUE_SIZE
#define CONFIG_BT_NIMBLE_HCI_EVT_LO_BUF_COUNT 1
#define CONFIG_BT_NIMBLE_MSYS1_BLOCK_COUNT 12
#define CONFIG_BT_NIMBLE_HS_FLOW_CTRL 1
#define CONFIG_BT_NIMBLE_HS_FLOW_CTRL_ITVL 1000
#define CONFIG_BT_NIMBLE_HS_FLOW_CTRL_THRESH 2
#define CONFIG_BT_NIMBLE_HS_FLOW_CTRL_TX_ON_DISCONNECT 1
#define CONFIG_BT_NIMBLE_RPA_TIMEOUT 900
#define CONFIG_BT_NIMBLE_CRYPTO_STACK_MBEDTLS 1
#if MESH_BLE_EN
#define CONFIG_BLE_MESH 1
#else
#define CONFIG_BLE_MESH 0
#endif
//#define CONFIG_BLE_MESH_HCI_5_0 1
#define CONFIG_BLE_MESH_FAST_PROV 0
#define CONFIG_BLE_MESH_NODE 1
#define CONFIG_BLE_MESH_PROVISIONER 1
#define CONFIG_BLE_MESH_WAIT_FOR_PROV_MAX_DEV_NUM 20
#define CONFIG_BLE_MESH_MAX_STORED_NODES 20
#define CONFIG_BLE_MESH_MAX_PROV_NODES 6
//#define CONFIG_BLE_MESH_PBA_SAME_TIME 0
//#define CONFIG_BLE_MESH_PBG_SAME_TIME 1
#define CONFIG_BLE_MESH_PROVISIONER_SUBNET_COUNT 3
#define CONFIG_BLE_MESH_PROVISIONER_APP_KEY_COUNT 3
#define CONFIG_BLE_MESH_PROV 1
#define CONFIG_BLE_MESH_PB_ADV 1
#define CONFIG_BLE_MESH_PB_GATT 1
#define CONFIG_BLE_MESH_PROXY 1
#define CONFIG_BLE_MESH_GATT_PROXY_SERVER 1
#define CONFIG_BLE_MESH_NODE_ID_TIMEOUT 60
#define CONFIG_BLE_MESH_PROXY_FILTER_SIZE 4
//#define CONFIG_BLE_MESH_NET_BUF_POOL_USAGE 1 //(Do not define if we want to disable)
#define CONFIG_BLE_MESH_SUBNET_COUNT 3
#define CONFIG_BLE_MESH_APP_KEY_COUNT 3
#define CONFIG_BLE_MESH_MODEL_KEY_COUNT 3
#define CONFIG_BLE_MESH_MODEL_GROUP_COUNT 9
#define CONFIG_BLE_MESH_LABEL_COUNT 3
#define CONFIG_BLE_MESH_CRPL 60
#define CONFIG_BLE_MESH_MSG_CACHE_SIZE 300
#define CONFIG_BLE_MESH_ADV_BUF_COUNT 200/*ssv*/
#define CONFIG_BLE_MESH_RELAY_ADV_BUF_COUNT 10

#define CONFIG_BLE_MESH_IVU_DIVIDER 4
#define CONFIG_BLE_MESH_TX_SEG_MSG_COUNT 2//5
#define CONFIG_BLE_MESH_RX_SEG_MSG_COUNT 50//5

/* 1.if less than 24, nRF Mesh provision fail
 * 2.MD test(item5) larger than 75
 */
#define CONFIG_BLE_MESH_RX_SDU_MAX 75
#define CONFIG_BLE_MESH_TX_SEG_MAX 8
#define CONFIG_BLE_MESH_RELAY 1
#define CONFIG_BLE_MESH_TRACE_LEVEL_ERROR 1
#define CONFIG_BLE_MESH_STACK_TRACE_LEVEL 2//1//
#define CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL_WARNING 1
#define CONFIG_BLE_MESH_NET_BUF_TRACE_LEVEL 3
#define CONFIG_BLE_MESH_CLIENT_MSG_TIMEOUT 4000
#define CONFIG_BLE_MESH_CFG_CLI 1


//#define CONFIG_SSV_SYSTEM_EVENT_TASK_STACK_SIZE 4096
//#define CONFIG_SSV_MAIN_TASK_STACK_SIZE 3584
//#define CONFIG_SSV_IPC_TASK_STACK_SIZE 1024
//#define CONFIG_SSV_IPC_USES_CALLERS_PRIORITY 1


#define CONFIG_SSV_TIMER_TASK_STACK_SIZE 2048
#define CONFIG_SSV_TIMER_IMPL_TG0_LAC 1

#define CONFIG_FREERTOS_NO_AFFINITY 0x7FFFFFFF
#define CONFIG_FREERTOS_CORETIMER_0 1
#define CONFIG_FREERTOS_HZ 1000
#define CONFIG_FREERTOS_ASSERT_ON_UNTESTED_FUNCTION 1
#define CONFIG_FREERTOS_CHECK_STACKOVERFLOW_CANARY 1
#define CONFIG_FREERTOS_INTERRUPT_BACKTRACE 1
#define CONFIG_FREERTOS_THREAD_LOCAL_STORAGE_POINTERS 1
#define CONFIG_FREERTOS_ASSERT_FAIL_ABORT 1
#define CONFIG_FREERTOS_IDLE_TASK_STACKSIZE 1536
#define CONFIG_FREERTOS_ISR_STACKSIZE 1536
#define CONFIG_FREERTOS_MAX_TASK_NAME_LEN 16
#define CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION 1
#define CONFIG_FREERTOS_TIMER_TASK_PRIORITY 1
#define CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH 2048
#define CONFIG_FREERTOS_TIMER_QUEUE_LENGTH 10
#define CONFIG_FREERTOS_QUEUE_REGISTRY_SIZE 0
#define CONFIG_FREERTOS_TASK_FUNCTION_WRAPPER 1
#define CONFIG_FREERTOS_CHECK_MUTEX_GIVEN_BY_OWNER 1
#define CONFIG_FREERTOS_DEBUG_OCDAWARE 1

#define CONFIG_LOG_DEFAULT_LEVEL_INFO 1
#define CONFIG_LOG_DEFAULT_LEVEL 3 /*log level*/
//#define CONFIG_LOG_COLORS 1

/* List of deprecated options */

#define CONFIG_BLE_ADV_REPORT_DISCARD_THRSHOLD CONFIG_BTDM_BLE_ADV_REPORT_DISCARD_THRSHOLD
#define CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_NUM CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_NUM
#define CONFIG_BLE_ADV_REPORT_FLOW_CONTROL_SUPPORTED CONFIG_BTDM_BLE_ADV_REPORT_FLOW_CTRL_SUPP
#define CONFIG_BLE_MESH_GATT_PROXY CONFIG_BLE_MESH_GATT_PROXY_SERVER
#define CONFIG_BLE_MESH_SCAN_DUPLICATE_EN CONFIG_BTDM_BLE_MESH_SCAN_DUPL_EN
#define CONFIG_BLE_SCAN_DUPLICATE CONFIG_BTDM_BLE_SCAN_DUPL

#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN CONFIG_BTDM_CTRL_BLE_MAX_CONN
#define CONFIG_BTDM_CONTROLLER_FULL_SCAN_SUPPORTED CONFIG_BTDM_CTRL_FULL_SCAN_SUPPORTED
#define CONFIG_BTDM_CONTROLLER_HCI_MODE_VHCI CONFIG_BTDM_CTRL_HCI_MODE_VHCI
#define CONFIG_BTDM_CONTROLLER_MODE_BLE_ONLY CONFIG_BTDM_CTRL_MODE_BLE_ONLY

#define CONFIG_DUPLICATE_SCAN_CACHE_SIZE CONFIG_BTDM_SCAN_DUPL_CACHE_SIZE


//#define CONFIG_IPC_TASK_STACK_SIZE CONFIG_SSV_IPC_TASK_STACK_SIZE

//#define CONFIG_MAIN_TASK_STACK_SIZE CONFIG_SSV_MAIN_TASK_STACK_SIZE

#define CONFIG_MESH_DUPLICATE_SCAN_CACHE_SIZE CONFIG_BTDM_MESH_DUPL_SCAN_CACHE_SIZE

#define CONFIG_SCAN_DUPLICATE_BY_ADV_DATA_AND_DEVICE_ADDR CONFIG_BTDM_SCAN_DUPL_TYPE_DATA_DEVICE

#define CONFIG_SUPPORT_STATIC_ALLOCATION CONFIG_FREERTOS_SUPPORT_STATIC_ALLOCATION

//#define CONFIG_SYSTEM_EVENT_TASK_STACK_SIZE CONFIG_SSV_SYSTEM_EVENT_TASK_STACK_SIZE

#define CONFIG_TIMER_QUEUE_LENGTH CONFIG_FREERTOS_TIMER_QUEUE_LENGTH
#define CONFIG_TIMER_TASK_PRIORITY CONFIG_FREERTOS_TIMER_TASK_PRIORITY
#define CONFIG_TIMER_TASK_STACK_DEPTH CONFIG_FREERTOS_TIMER_TASK_STACK_DEPTH
#define CONFIG_TIMER_TASK_STACK_SIZE CONFIG_SSV_TIMER_TASK_STACK_SIZE

